package cn.edu.java.io.outputstream;

import cn.edu.java.object.Person;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;


public class ObjectOutputStreamDemo {
    public static void main(String[] args) {
        // 创建一个Person对象
        Person person = new Person("Alice", 25);

        // 将对象写入文件
        try (ObjectOutputStream objectOut = new ObjectOutputStream(new FileOutputStream("output/person.ser"))) {
            objectOut.writeObject(person);
            System.out.println("对象已成功写入文件!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

